package com.wlb365.financing.modules.orgaccount.service.impl;

import cn.hutool.json.JSONUtil;
import com.google.common.collect.Maps;
import com.wlb365.financing.common.constants.ApiConstants;
import com.wlb365.financing.common.utils.ShiroUtil;
import com.wlb365.financing.modules.orgaccount.request.OrgAccountAddReq;
import com.wlb365.financing.modules.orgaccount.request.OrgAccountQueryPageReq;
import com.wlb365.financing.modules.orgaccount.response.OrgAccountAddRes;
import com.wlb365.financing.modules.orgaccount.response.OrgAccountPageRes;
import com.wlb365.financing.modules.orgaccount.service.IOrgAccountService;
import com.wlb365.financing.modules.sys.service.IDeptService;
import com.wlb365.sdk.client.SdkClient;
import com.wlb365.sdk.model.CommonRequest;
import com.wlb365.sdk.model.CommonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * @Author LuHang
 * @Date 2021/5/25 13:30
 * @Version 1.0
 */
@Service
public class OrgAccountServiceImpl implements IOrgAccountService {
    @Autowired
    private SdkClient sdkClient;

    @Override
    public OrgAccountAddRes add(OrgAccountAddReq orgAccountAddReq) {
        CommonRequest commonRequest = new CommonRequest(ApiConstants.FS_CUSTOMER_ORG_ACCOUNT_ADD);
        Map<String, Object> params = Maps.newHashMap();
        params.put("compId", orgAccountAddReq.getCompId());
        params.put("acctNo", orgAccountAddReq.getAcctNo());
        params.put("acctName", orgAccountAddReq.getAcctName());
        params.put("acctPhone", orgAccountAddReq.getAcctPhone());
        params.put("bankName", orgAccountAddReq.getBankName());
        params.put("bankId", orgAccountAddReq.getBankId());
        params.put("createBy", ShiroUtil.getUser().getUsername());
        commonRequest.setBizModel(params);
        CommonResponse commonResponse =  sdkClient.execute(commonRequest);
        OrgAccountAddRes orgAccountAddRes = JSONUtil.toBean(commonResponse.getData(),OrgAccountAddRes.class);
        return orgAccountAddRes;
    }

    @Override
    public OrgAccountPageRes listData(OrgAccountQueryPageReq orgAccountQueryPageReq) {
        CommonRequest commonRequest = new CommonRequest(ApiConstants.FS_CUSTOMER_ORG_ACCOUNT_PAGE);
        Map<String, Object> params = Maps.newHashMap();
        params.put("compId", orgAccountQueryPageReq.getCompId());
        commonRequest.setBizModel(params);
        CommonResponse commonResponse =  sdkClient.execute(commonRequest);
        OrgAccountPageRes orgAccountPageRes = JSONUtil.toBean(commonResponse.getData(),OrgAccountPageRes.class);
        return orgAccountPageRes;
    }
}
